package net.ttny.java.m1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import net.ttny.java.m1.entity.User;
import net.ttny.java.m1.service.impl.UserServiceImpl;
  
@Controller

public class LoginController {
	@Autowired
    private UserServiceImpl UserService;
	
	@RequestMapping("/login")
	public String index() {
		return "login";
	}
	
	@RequestMapping("/dologin")
	public String dologin(User user, Model model) {
	    if(UserService.doUserLogin(user)) {
	        model.addAttribute("successMsg", "登录成功！");//返回到页面所夹带的参数  
	        model.addAttribute("name", user.getNick_name());
	        return "/success";//返回的页面  
	    } else {
	        model.addAttribute("failMsg", "用户不存在或密码错误！");
	        return "/fail";
	    }
	}
}
